package cn.dulian.fruit.servlets;

import cn.dulian.fruit.dao.FruitDAO;
import cn.dulian.fruit.dao.impl.FruitDAOImpl;
import cn.dulian.fruit.pojo.Fruit;
import cn.dulian.myssm.myspringmvc.ViewBaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @author dulian
 * @create 2022-04-07 10:49
 */

@WebServlet("/index")
public class IndexServlet extends ViewBaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        FruitDAO fruitDAO = new FruitDAOImpl();
        List<Fruit> fruitList = fruitDAO.getFruitList();
        //保存到session作用域中
        HttpSession session = req.getSession();
        session.setAttribute("fruitList",fruitList);
        //此处视图名称是index
        //那么thymeleaf会将这个 逻辑视图名称 对应到物理视图 名称上去
        //逻辑视图名称： Index
        //物理视图名称： view-prefix + 逻辑视图名称+ view-suffix
        //所以真实的视图名称是： / index .html
        super.processTemplate("index",req,resp);
    }

}
